<h2>Inspected Network Tutorial</h2>

<p>This tutorial extends Tutorial5 to show how to attach a Social Networks inspector to the graph.  This isn't all that interesting as the graph is static and several of the inspected distributions are not valid as a result.  But it'll get you the idea.

<p>This tutorial teaches:
<ul>
<li> How to connect a social network inspector
</ul>

<h2>Copy the class</h2>

<p>Copy the file <b>sim/app/tutorial5/Tutorial5WithUI.java</b> to a new file called <b>sim/app/inspectednetwork/InspectedNetworkWithUI.java</b>.  Change

<p><table border=1>
<tr><td align=center><b>FROM...</b></td><td align=center><b>CHANGE TO</b></td>
<tr><td><pre><tt>
package sim.app.tutorial5;
import sim.portrayal.network.*;
import sim.portrayal.continuous.*;
import sim.engine.*;
import sim.display.*;
import javax.swing.*;
import java.awt.Color;


public class Tutorial5WithUI extends GUIState

</tt></pre></td><td><pre><tt>
<font color=blue>
package sim.app.inspectednetwork;
import sim.app.tutorial5.*;
import sim.portrayal.network.stats.*;
</font>
import sim.portrayal.network.*;
import sim.portrayal.continuous.*;
import sim.engine.*;
import sim.display.*;
import javax.swing.*;
import java.awt.Color;


<font color=blue>
public class InspectedNetworkWithUI extends GUIState
</font>
</tt></pre></td></tr></table>

<p>Additionally you of course need to update the constructor names.  Change
<p><table border=1>
<tr><td align=center><b>FROM...</b></td><td align=center><b>CHANGE TO</b></td>
<tr><td><pre><tt>
    public static void main(String[] args)
        {
        Tutorial5WithUI vid = new Tutorial5WithUI();
        Console c = new Console(vid);
        c.setVisible(true);
        }

    public Tutorial5WithUI() { super(new Tutorial5( System.currentTimeMillis())); }
    public Tutorial5WithUI(SimState state) { super(state); }
</tt></pre></td><td><pre><tt>
    public static void main(String[] args)
        {
<font color=blue>        InspectedNetworkWithUI vid = new InspectedNetworkWithUI();</font>
        Console c = new Console(vid);
        c.setVisible(true);
        }

<font color=blue>
    public InspectedNetworkWithUI() { super(new Tutorial5( System.currentTimeMillis())); }
    public InspectedNetworkWithUI(SimState state) { super(state); }
</font>
</tt></pre></td></tr></table>

<p>You might also wish to change the getInfo() method, or delete it and provide an index.html file talking about the InspectedNetwork example (we do that in the example code).

 
<h2>Add the SocialNetworkInspector</h2>

<p>SocialNetworkInspectors operate much like Portrayals -- they get attached to a Display and appear in its menu of Portrayal options.  To make an inspector just change:

<p><table border=1>
<tr><td align=center><b>FROM...</b></td><td align=center><b>CHANGE TO</b></td>
<tr><td><pre><tt>
    NetworkPortrayal2D edgePortrayal = new NetworkPortrayal2D();
    ContinuousPortrayal2D nodePortrayal = new ContinuousPortrayal2D();
</tt></pre></td><td><pre><tt>
    NetworkPortrayal2D edgePortrayal = new NetworkPortrayal2D();
    ContinuousPortrayal2D nodePortrayal = new ContinuousPortrayal2D();
<font color=blue>
    SocialNetworkInspector inspector = new SocialNetworkInspector();
</font>
</tt></pre></td></tr></table>

<p>Now we need to set up the inspector just as the portrayals are being set up.  In <b>setupPortrayals()</b>, change:

<p><table border=1>
<tr><td align=center><b>FROM...</b></td><td align=center><b>CHANGE TO</b></td>
<tr><td><pre><tt>
        edgePortrayal.setField( new SpatialNetwork2D( tut.balls, tut.bands ) );
        edgePortrayal.setPortrayalForAll(new BandPortrayal2D());
        nodePortrayal.setField( tut.balls );
</tt></pre></td><td><pre><tt>
        edgePortrayal.setField( new SpatialNetwork2D( tut.balls, tut.bands ) );
        edgePortrayal.setPortrayalForAll(new BandPortrayal2D());
        nodePortrayal.setField( tut.balls );
<font color=blue>
        
        inspector.setField(tut.bands, this);
</font>
</tt></pre></td></tr></table>

<p>This tells the inspector it's supposed to inspect the <b>tut.bands</b> Network.  Last, we need to attach it to a Display2D.  Change:

<p><table border=1>
<tr><td align=center><b>FROM...</b></td><td align=center><b>CHANGE TO</b></td>
<tr><td><pre><tt>
        display.attach( edgePortrayal, "Bands" );
        display.attach( nodePortrayal, "Balls" );
</tt></pre></td><td><pre><tt>
        display.attach( edgePortrayal, "Bands" );
        display.attach( nodePortrayal, "Balls" );
<font color=blue>
        display.attach( inspector, "Inspector" );
</font>
</tt></pre></td></tr></table>

<h2>Try it out</h2>

That's it!  Save and compile the file.  Then run <b>java sim.app.inspectednetwork.InspectedNetworkWithUI</b>

<p>Press Play.  When the balls are bouncing around, look under the Layers menu on the Tutorial 5 Display.  Notice it now says "Show Inspector".  Choose this, and the inspector will pop up.  Given the network provided, it's expected that Node Eccentricity should be uniform, and likewise the Diameters should be infinity.

 
